import { ParseIntPipe,BadRequestException } from '@nestjs/common';
import * as crypto from 'crypto';

export function md5(str: string) {
  // 创建一个MD5 hash对象
  const hash = crypto.createHash('md5');

  // 更新hash对象，传入要计算哈希的字符串
  hash.update(str);

  // 计算哈希值
  const hex = hash.digest('hex');

  return hex;
}
export function generateParseIntPipe(name) {
  return new ParseIntPipe({
    exceptionFactory() {
      throw new BadRequestException(name + ' 应该传数字');
    } 
  })
}